<!DOCTYPE HTML>
<html lang="zh-CN">


<head><meta name="generator" content="Hexo 3.8.0">
    <meta charset="utf-8">
    <meta name="keywords" content="【Linux】设备树基础知识, ZhengN_Blog">
    <meta name="description" content="前言之前分享的笔记：【Linux笔记】总线设备驱动模型中在platform_device部分有简单说明描述设备有两种方法：一种是使用platform_device结构体来指定；另一种是使用设备树来描述。本篇笔记我们就来简单地学习一下设备树的">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <title>【Linux】设备树基础知识 | ZhengN_Blog</title>
    <link rel="icon" type="image/jpeg" href="/favicon.jpg">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">
    <style type="text/css">
        
    </style>

    <script src="/libs/jquery/jquery-2.2.0.min.js"></script>
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css"></head>


<body>

<header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">ZhengN_Blog</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fa fa-navicon"></i></a>
<ul class="right">
    
    <li class="hide-on-med-and-down">
        <a href="/" class="waves-effect waves-light">
            
            <i class="fa fa-home"></i>
            
            <span>首页</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/tags" class="waves-effect waves-light">
            
            <i class="fa fa-tags"></i>
            
            <span>标签</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/categories" class="waves-effect waves-light">
            
            <i class="fa fa-bookmark"></i>
            
            <span>分类</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/archives" class="waves-effect waves-light">
            
            <i class="fa fa-archive"></i>
            
            <span>归档</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/about" class="waves-effect waves-light">
            
            <i class="fa fa-user-circle-o"></i>
            
            <span>关于</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/friends" class="waves-effect waves-light">
            
            <i class="fa fa-address-book"></i>
            
            <span>友情链接</span>
        </a>
    </li>
    
    <li>
        <a href="#searchModal" class="modal-trigger waves-effect waves-light">
            <i id="searchIcon" class="fa fa-search" title="搜索"></i>
        </a>
    </li>
</ul>

<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">ZhengN_Blog</div>
        <div class="logo-desc">
            
            printf(&#34;每天进步一点点~&#34;);
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li>
            <a href="/" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-home"></i>
                
                首页
            </a>
        </li>
        
        <li>
            <a href="/tags" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-tags"></i>
                
                标签
            </a>
        </li>
        
        <li>
            <a href="/categories" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-bookmark"></i>
                
                分类
            </a>
        </li>
        
        <li>
            <a href="/archives" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-archive"></i>
                
                归档
            </a>
        </li>
        
        <li>
            <a href="/about" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-user-circle-o"></i>
                
                关于
            </a>
        </li>
        
        <li>
            <a href="/friends" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-address-book"></i>
                
                友情链接
            </a>
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/zhengnianli/stm32_weather" class="waves-effect waves-light" target="_blank">
                <i class="fa fa-github-square fa-fw"></i>Fork Me
            </a>
        </li>
        
    </ul>
</div>

        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/zhengnianli/stm32_weather" class="github-corner tooltipped hide-on-med-and-down" target="_blank" data-tooltip="Fork Me" data-position="left" data-delay="50">
    <svg viewbox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/>
    </svg>
</a>
        
    </nav>

</header>





<div class="bg-cover pd-header post-cover" style="background-image: url('/medias/featureimages/14.jpg')">
    <div class="container">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <div class="description center-align post-title">
                        【Linux】设备树基础知识
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>



<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        margin: 35px 0 15px 0;
        padding-left: 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #toc-content .is-active-link::before {
        background-color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 20px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/Linux/" target="_blank">
                                <span class="chip bg-color">Linux</span>
                            </a>
                        
                            <a href="/tags/驱动/" target="_blank">
                                <span class="chip bg-color">驱动</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fa fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/categories/Linux/" class="post-category" target="_blank">
                                Linux
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                <div class="post-date info-break-policy">
                    <i class="fa fa-calendar-minus-o fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2020-04-11
                </div>

                
                    
                    <div class="info-break-policy">
                        <i class="fa fa-file-word-o fa-fw"></i>文章字数:&nbsp;&nbsp;
                        2.2k
                    </div>
                    

                    
                    <div class="info-break-policy">
                        <i class="fa fa-clock-o fa-fw"></i>阅读时长:&nbsp;&nbsp;
                        8 分
                    </div>
                    
                
				
				
                    <div id="busuanzi_container_page_pv" class="info-break-policy">
                        <i class="fa fa-eye fa-fw"></i>阅读次数:&nbsp;&nbsp;
                        <span id="busuanzi_value_page_pv"></span>
                    </div>
				
            </div>
        </div>
        <hr class="clearfix">
        <div class="card-content article-card-content">
            <div id="articleContent">
                <h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>之前分享的笔记：<a href="http://mp.weixin.qq.com/s?__biz=MzU5MzcyMjI4MA==&mid=100003346&idx=1&sn=20ca3d01d296ec99def8910291bc0754&chksm=7e0d60d5497ae9c3adb7b1a5f492cd5c1965121ac85ed22c1a58636318542ce69bd191535fa3#rd" target="_blank" rel="noopener">【Linux笔记】总线设备驱动模型</a>中在platform_device部分有简单说明描述设备有两种方法：一种是使用platform_device结构体来指定；另一种是使用<code>设备树</code>来描述。本篇笔记我们就来简单地学习一下设备树的一些知识。</p>
<h2 id="什么是设备树"><a href="#什么是设备树" class="headerlink" title="什么是设备树"></a>什么是设备树</h2><p><img src="https://s1.ax1x.com/2020/04/20/J3e1DH.png" alt></p>
<p>设备树简单理解就是描述设备信息（资源）的一棵树。<code>设备树（Device Tree）</code>用代码体现如下：</p>
<p><img src="https://s1.ax1x.com/2020/04/20/J3eu8K.png" alt></p>
<p>这些代码被保存在<code>.dts/dtsi</code>后缀文件中，也即设备树源文件 <code>DTS(DeviceTree Source)</code>。这些源文件同我们的C代码一样，并不能直接使用的，而是得经过一个编译过程生成机器可运行的二进制文件，如：</p>
<p><img src="https://s1.ax1x.com/2020/04/20/J3eKgO.png" alt></p>
<p>dts文件使用dtc工具编译生成dtb文件，这个dtb文件就是内核可以使用的文件。例如我们的板子跑起来之后，我们系统使用的设备树文件就存在目录/boot下：</p>
<p><img src="https://s1.ax1x.com/2020/04/20/J3eMvD.png" alt></p>
<h2 id="Linux为什么会引入设备树？"><a href="#Linux为什么会引入设备树？" class="headerlink" title="Linux为什么会引入设备树？"></a>Linux为什么会引入设备树？</h2><p>在上一个实验：<a href="http://mp.weixin.qq.com/s?__biz=MzU5MzcyMjI4MA==&mid=100003379&idx=1&sn=cc8ef6eeb4fa3d4ff87e950786821e98&chksm=7e0d60f4497ae9e24006b796c8a16610f41b324dbd907a3dc3d7a5c48d19b0c2eaa7ae75c3fc#rd" target="_blank" rel="noopener">【Linux笔记】LED驱动实验（总线设备驱动模型）</a>中我们使用了platform_device结构体来描述led设备（硬件资源）。既然已经有了描述设备的方法了，为什么还要引入设备树呢？因为Linux内核中有很多BSP（板级支持包），不同的BSP会包含着不同的描述设备的代码（.c或.h文件）。随着芯片的发展，Linux内核中就包含着越来越多这些描述设备的代码，导致Linux内核代码会很臃肿。</p>
<p>这导致Linux之父Linus 大发雷霆： “this whole ARM thing is a f*cking pain in the ass”。 因此引入了设备树文件，从而可精简一些臃肿的C代码。除此之外，.dts编译生成.dtb文件的过程要比.c编译生成驱动模块、加载驱动模块的过程要简单很多，也更方面我们进行开发。</p>
<h2 id="设备树的语法"><a href="#设备树的语法" class="headerlink" title="设备树的语法"></a>设备树的语法</h2><p>设备树源文件也是需要根据一定规则来编写的，同C语言一样，也要遵循一些语法规则。下面简单看一下设备树的源码结构及语法。</p>
<p>先看一个设备树示例：</p>
<p><img src="https://s1.ax1x.com/2020/04/20/J3elKe.png" alt></p>
<h3 id="1、节点格式"><a href="#1、节点格式" class="headerlink" title="1、节点格式"></a>1、节点格式</h3><blockquote>
<p>label: node-name@unit-address </p>
</blockquote>
<p>其中：</p>
<blockquote>
<p>label：标号</p>
<p>node-name：节点名字</p>
<p>unit-address：单元地址</p>
</blockquote>
<p>label 是标号，可以省略。 label 的作用是为了方便地引用 node。比如：</p>
<p><img src="https://s1.ax1x.com/2020/04/20/J3e3bd.png" alt></p>
<p>可以使用下面 2 种方法来修改 uart@fe001000 这个 node： </p>
<p><img src="https://s1.ax1x.com/2020/04/20/J3eGVA.png" alt></p>
<h3 id="2、属性格式"><a href="#2、属性格式" class="headerlink" title="2、属性格式"></a>2、属性格式</h3><p>简单地说， properties 就是“name=value”， value 有多种取值方式。 示例：</p>
<ul>
<li>一个32位的数据，用尖括号包围起来，如</li>
</ul>
<pre class=" language-c"><code class="language-c">interrupts <span class="token operator">=</span> <span class="token operator">&lt;</span><span class="token number">17</span> <span class="token number">0xc</span><span class="token operator">></span><span class="token punctuation">;</span>   </code></pre>
<ul>
<li>一个64位数据（使用2个32位数据表示），用尖括号包围起来，如：</li>
</ul>
<pre class=" language-c"><code class="language-c">clock<span class="token operator">-</span>frequency <span class="token operator">=</span> <span class="token operator">&lt;</span><span class="token number">0x00000001</span> <span class="token number">0x00000000</span><span class="token operator">></span><span class="token punctuation">;</span>   </code></pre>
<ul>
<li>有结束符的字符串，用双引号包围起来，如：</li>
</ul>
<pre class=" language-c"><code class="language-c">compatible <span class="token operator">=</span> <span class="token string">"simple-bus"</span><span class="token punctuation">;</span>   </code></pre>
<ul>
<li>字节序列，用中括号包围起来，如：</li>
</ul>
<pre class=" language-c"><code class="language-c">local<span class="token operator">-</span>mac<span class="token operator">-</span>address <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">00</span> <span class="token number">00</span> <span class="token number">12</span> <span class="token number">34</span> <span class="token number">56</span> <span class="token number">78</span><span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">// 每个byte使用2个16进制数来表示   </span>
local<span class="token operator">-</span>mac<span class="token operator">-</span>address <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">000012345678</span><span class="token punctuation">]</span><span class="token punctuation">;</span>      <span class="token comment" spellcheck="true">// 每个byte使用2个16进制数来表示   </span></code></pre>
<ul>
<li>可以是各种值的组合，用逗号隔开，如：</li>
</ul>
<pre class=" language-c"><code class="language-c">compatible <span class="token operator">=</span> <span class="token string">"ns16550"</span><span class="token punctuation">,</span> <span class="token string">"ns8250"</span><span class="token punctuation">;</span>   
example <span class="token operator">=</span> <span class="token operator">&lt;</span><span class="token number">0xf00f0000</span> <span class="token number">19</span><span class="token operator">></span><span class="token punctuation">,</span> <span class="token string">"a strange property format"</span><span class="token punctuation">;</span>   </code></pre>
<h3 id="3、一些标准属性"><a href="#3、一些标准属性" class="headerlink" title="3、一些标准属性"></a>3、一些标准属性</h3><h4 id="（1）-compatible-属性"><a href="#（1）-compatible-属性" class="headerlink" title="（1） compatible 属性"></a>（1） compatible 属性</h4><p>“compatible”表示“兼容”，对于某个LED，内核中可能有A、B、C三个驱动都支持它，那可以这样写：</p>
<pre class=" language-c"><code class="language-c">led <span class="token punctuation">{</span>   
    compatible <span class="token operator">=</span> “A”<span class="token punctuation">,</span> “B”<span class="token punctuation">,</span> “C”<span class="token punctuation">;</span>   
<span class="token punctuation">}</span><span class="token punctuation">;</span>  </code></pre>
<p>内核启动时，就会为这个LED按这样的优先顺序为它找到驱动程序：A、B、C。</p>
<h4 id="（2）model-属性"><a href="#（2）model-属性" class="headerlink" title="（2）model 属性"></a>（2）model 属性</h4><p>model属性与compatible属性有些类似，但是有差别。compatible属性是一个字符串列表，表示可以你的硬件兼容A、B、C等驱动；model用来准确地定义这个硬件是什么。比如根节点中可以这样写：</p>
<pre class=" language-c"><code class="language-c"><span class="token operator">/</span> <span class="token punctuation">{</span>   
    compatible <span class="token operator">=</span> <span class="token string">"samsung,smdk2440"</span><span class="token punctuation">,</span> <span class="token string">"samsung,mini2440"</span><span class="token punctuation">;</span>   
    model <span class="token operator">=</span> <span class="token string">"jz2440_v3"</span><span class="token punctuation">;</span>   
<span class="token punctuation">}</span><span class="token punctuation">;</span>  </code></pre>
<p>它表示这个单板，可以兼容内核中的“smdk2440”，也兼容“mini2440”。从compatible属性中可以知道它兼容哪些板，但是它到底是什么板？用model属性来明确。</p>
<h4 id="（3）status-属性"><a href="#（3）status-属性" class="headerlink" title="（3）status 属性"></a>（3）status 属性</h4><p>status 属性看名字就知道是和设备状态有关的， status 属性值也是字符串，字符串是设备的状态信息，可选的状态如下所示：</p>
<p><img src="https://s1.ax1x.com/2020/04/20/J3eY5t.png" alt></p>
<h4 id="（4）-address-cells-和-size-cells-属性"><a href="#（4）-address-cells-和-size-cells-属性" class="headerlink" title="（4）#address-cells 和#size-cells 属性"></a>（4）#address-cells 和#size-cells 属性</h4><p>格式：</p>
<pre class=" language-c"><code class="language-c">address<span class="token operator">-</span>cells：address要用多少个<span class="token number">32</span>位数来表示；   
size<span class="token operator">-</span>cells：size要用多少个<span class="token number">32</span>位数来表示。 </code></pre>
<p>比如一段内存，怎么描述它的起始地址和大小？下例中，address-cells为1，所以reg中用1个数来表示地址，即用0x80000000来表示地址；size-cells为1，所以reg中用1个数来表示大小，即用0x20000000表示大小：</p>
<pre class=" language-c"><code class="language-c"><span class="token operator">/</span> <span class="token punctuation">{</span>   
    <span class="token macro property"># address-cells = &lt;1>;   </span>
    <span class="token macro property"># size-cells = &lt;1>;   </span>
    memory <span class="token punctuation">{</span>   
        reg <span class="token operator">=</span> <span class="token operator">&lt;</span><span class="token number">0x80000000</span> <span class="token number">0x20000000</span><span class="token operator">></span><span class="token punctuation">;</span>   
    <span class="token punctuation">}</span><span class="token punctuation">;</span>   
<span class="token punctuation">}</span><span class="token punctuation">;</span>   </code></pre>
<h4 id="（5）reg-属性"><a href="#（5）reg-属性" class="headerlink" title="（5）reg 属性"></a>（5）reg 属性</h4><p>reg的本意是register，用来表示寄存器地址。但是在设备树里，它可以用来描述一段空间。反正对于ARM系统，寄存器和内存是统一编址的，即访问寄存器时用某块地址，访问内存时用某块地址，在访问方法上没有区别。</p>
<p>reg属性的值，是一系列的“address size”，用多少个32位的数来表示address和size，由其父节点的# address-cells、#size-cells决定。示例：</p>
<pre class=" language-c"><code class="language-c"><span class="token operator">/</span>dts<span class="token operator">-</span>v1<span class="token operator">/</span><span class="token punctuation">;</span>   
<span class="token operator">/</span> <span class="token punctuation">{</span>   
    <span class="token macro property"># address-cells = &lt;1>;   </span>
    <span class="token macro property"># size-cells = &lt;1>;   </span>
    memory <span class="token punctuation">{</span>   
        reg <span class="token operator">=</span> <span class="token operator">&lt;</span><span class="token number">0x80000000</span> <span class="token number">0x20000000</span><span class="token operator">></span><span class="token punctuation">;</span>   
    <span class="token punctuation">}</span><span class="token punctuation">;</span>   
<span class="token punctuation">}</span><span class="token punctuation">;</span>   </code></pre>
<h4 id="（7）name-属性"><a href="#（7）name-属性" class="headerlink" title="（7）name 属性"></a>（7）name 属性</h4><p>过时了，建议不用。它的值是字符串，用来表示节点的名字。在跟platform_driver匹配时，优先级最低。compatible属性在匹配过程中，优先级最高。</p>
<h4 id="（8）device-type-属性"><a href="#（8）device-type-属性" class="headerlink" title="（8）device_type 属性"></a>（8）device_type 属性</h4><p>过时了，建议不用。它的值是字符串，用来表示节点的类型。在跟platform_driver匹配时，优先级为中。compatible属性在匹配过程中，优先级最高。</p>
<h3 id="3、常用的节点"><a href="#3、常用的节点" class="headerlink" title="3、常用的节点"></a>3、常用的节点</h3><h4 id="（1）根节点"><a href="#（1）根节点" class="headerlink" title="（1）根节点"></a>（1）根节点</h4><p>用 / 标识根节点，如：</p>
<pre class=" language-c"><code class="language-c"><span class="token operator">/</span>dts<span class="token operator">-</span>v1<span class="token operator">/</span><span class="token punctuation">;</span>   
<span class="token operator">/</span> <span class="token punctuation">{</span>   
    model <span class="token operator">=</span> <span class="token string">"SMDK24440"</span><span class="token punctuation">;</span>   
    compatible <span class="token operator">=</span> <span class="token string">"samsung,smdk2440"</span><span class="token punctuation">;</span>   

    <span class="token macro property"># address-cells = &lt;1>;   </span>
    <span class="token macro property"># size-cells = &lt;1>;   </span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>   </code></pre>
<h4 id="（2）CPU节点"><a href="#（2）CPU节点" class="headerlink" title="（2）CPU节点"></a>（2）CPU节点</h4><p>一般不需要我们设置，在 dtsi 文件中都定义好了，如：</p>
<pre class=" language-c"><code class="language-c">cpus <span class="token punctuation">{</span>   
    <span class="token macro property"># address-cells = &lt;1>;   </span>
    <span class="token macro property"># size-cells = &lt;0>;   </span>

    cpu0<span class="token punctuation">:</span> cpu@<span class="token number">0</span> <span class="token punctuation">{</span>   
        <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>   
    <span class="token punctuation">}</span>   
<span class="token punctuation">}</span><span class="token punctuation">;</span>   </code></pre>
<h4 id="（3）memory-节点"><a href="#（3）memory-节点" class="headerlink" title="（3）memory 节点"></a>（3）memory 节点</h4><p>芯片厂家不可能事先确定你的板子使用多大的内存，所以 memory 节点需要板厂设置，比如： </p>
<pre class=" language-c"><code class="language-c">memory <span class="token punctuation">{</span>   
    reg <span class="token operator">=</span> <span class="token operator">&lt;</span><span class="token number">0x80000000</span> <span class="token number">0x20000000</span><span class="token operator">></span><span class="token punctuation">;</span>   
<span class="token punctuation">}</span><span class="token punctuation">;</span> </code></pre>
<h4 id="（4）chosen-节点"><a href="#（4）chosen-节点" class="headerlink" title="（4）chosen 节点"></a>（4）chosen 节点</h4><p>我们可以通过设备树文件给内核传入一些参数，这要在chosen节点中设置bootargs属性：</p>
<pre class=" language-c"><code class="language-c">chosen <span class="token punctuation">{</span>   
    bootargs <span class="token operator">=</span> <span class="token string">"noinitrd root=/dev/mtdblock4 rw init=/linuxrc console=ttySAC0,115200"</span><span class="token punctuation">;</span>   
<span class="token punctuation">}</span><span class="token punctuation">;</span>   </code></pre>
<h2 id="操作设备树的函数"><a href="#操作设备树的函数" class="headerlink" title="操作设备树的函数"></a>操作设备树的函数</h2><p>Linux 内核给我们提供了一系列的函数来获取设备树中的节点或者属性信息，这一系列的函数都有一个统一的前缀“of_”（“open firmware”即开放固件。 ），所以在很多资料里面也被叫做 OF 函数。</p>
<h3 id="1、节点相关操作函数"><a href="#1、节点相关操作函数" class="headerlink" title="1、节点相关操作函数"></a>1、节点相关操作函数</h3><p>Linux 内核使用 device_node 结构体来描述一个节点，此结构体定义在文件 include/linux/of.h 中，定义如下： </p>
<p><img src="https://s1.ax1x.com/2020/04/20/J3eNPP.png" alt></p>
<p>与查找节点有关的 OF 函数有 5 个：</p>
<h4 id="（1）-of-find-node-by-name-函数"><a href="#（1）-of-find-node-by-name-函数" class="headerlink" title="（1） of_find_node_by_name 函数"></a>（1） of_find_node_by_name 函数</h4><p>of_find_node_by_name 函数通过节点名字查找指定的节点，函数原型如下： </p>
<pre class=" language-c"><code class="language-c"><span class="token keyword">struct</span> device_node <span class="token operator">*</span><span class="token function">of_find_node_by_name</span><span class="token punctuation">(</span><span class="token keyword">struct</span> device_node <span class="token operator">*</span>from<span class="token punctuation">,</span>
<span class="token keyword">const</span> <span class="token keyword">char</span> <span class="token operator">*</span>name<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
<h4 id="（2）-of-find-node-by-type-函数"><a href="#（2）-of-find-node-by-type-函数" class="headerlink" title="（2） of_find_node_by_type 函数"></a>（2） of_find_node_by_type 函数</h4><p>of_find_node_by_type 函数通过 device_type 属性查找指定的节点，函数原型如下： </p>
<pre class=" language-c"><code class="language-c"><span class="token keyword">struct</span> device_node <span class="token operator">*</span><span class="token function">of_find_node_by_type</span><span class="token punctuation">(</span><span class="token keyword">struct</span> device_node <span class="token operator">*</span>from<span class="token punctuation">,</span> <span class="token keyword">const</span> <span class="token keyword">char</span> <span class="token operator">*</span>type<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
<h4 id="（3）-of-find-compatible-node-函数"><a href="#（3）-of-find-compatible-node-函数" class="headerlink" title="（3） of_find_compatible_node 函数"></a>（3） of_find_compatible_node 函数</h4><p>of_find_compatible_node 函数根据 device_type 和 compatible 这两个属性查找指定的节点，函数原型如下： </p>
<pre class=" language-c"><code class="language-c"><span class="token keyword">struct</span> device_node <span class="token operator">*</span><span class="token function">of_find_compatible_node</span><span class="token punctuation">(</span><span class="token keyword">struct</span> device_node <span class="token operator">*</span>from<span class="token punctuation">,</span><span class="token keyword">const</span> <span class="token keyword">char</span> <span class="token operator">*</span>type<span class="token punctuation">,</span>
<span class="token keyword">const</span> <span class="token keyword">char</span> <span class="token operator">*</span>compatible<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
<h4 id="（4）of-find-matching-node-and-match-函数"><a href="#（4）of-find-matching-node-and-match-函数" class="headerlink" title="（4）of_find_matching_node_and_match 函数"></a>（4）of_find_matching_node_and_match 函数</h4><p>of_find_matching_node_and_match 函数通过 of_device_id 匹配表来查找指定的节点，函数原型如下： </p>
<pre class=" language-c"><code class="language-c"><span class="token keyword">struct</span> device_node <span class="token operator">*</span><span class="token function">of_find_matching_node_and_match</span><span class="token punctuation">(</span><span class="token keyword">struct</span> device_node <span class="token operator">*</span>from<span class="token punctuation">,</span><span class="token keyword">const</span> <span class="token keyword">struct</span> of_device_id <span class="token operator">*</span>matches<span class="token punctuation">,</span><span class="token keyword">const</span> <span class="token keyword">struct</span> of_device_id <span class="token operator">*</span><span class="token operator">*</span>match<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
<h4 id="（5）of-find-node-by-path-函数"><a href="#（5）of-find-node-by-path-函数" class="headerlink" title="（5）of_find_node_by_path 函数"></a>（5）of_find_node_by_path 函数</h4><p>of_find_node_by_path 函数通过路径来查找指定的节点，函数原型如下： </p>
<pre class=" language-c"><code class="language-c"><span class="token keyword">inline</span> <span class="token keyword">struct</span> device_node <span class="token operator">*</span><span class="token function">of_find_node_by_path</span><span class="token punctuation">(</span><span class="token keyword">const</span> <span class="token keyword">char</span> <span class="token operator">*</span>path<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
<h3 id="2、提取属性值的-OF-函数"><a href="#2、提取属性值的-OF-函数" class="headerlink" title="2、提取属性值的 OF 函数"></a>2、提取属性值的 OF 函数</h3><p>Linux 内核中使用结构体 property 表示属性，此结构体同样定义在文件 include/linux/of.h 中，内容如下： </p>
<p><img src="https://s1.ax1x.com/2020/04/20/J3edxS.png" alt></p>
<p>Linux 内核也提供了提取属性值的 OF 函数 ：</p>
<h4 id="（1）-of-find-property-函数"><a href="#（1）-of-find-property-函数" class="headerlink" title="（1） of_find_property 函数"></a>（1） of_find_property 函数</h4><p>of_find_property 函数用于查找指定的属性，函数原型如下： </p>
<pre class=" language-c"><code class="language-c">property <span class="token operator">*</span><span class="token function">of_find_property</span><span class="token punctuation">(</span><span class="token keyword">const</span> <span class="token keyword">struct</span> device_node <span class="token operator">*</span>np<span class="token punctuation">,</span><span class="token keyword">const</span> <span class="token keyword">char</span> <span class="token operator">*</span>name<span class="token punctuation">,</span><span class="token keyword">int</span> <span class="token operator">*</span>lenp<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
<h4 id="（2）of-property-count-elems-of-size-函数"><a href="#（2）of-property-count-elems-of-size-函数" class="headerlink" title="（2）of_property_count_elems_of_size 函数"></a>（2）of_property_count_elems_of_size 函数</h4><p>of_property_count_elems_of_size 函数用于获取属性中元素的数量，比如 reg 属性值是一个数组，那么使用此函数可以获取到这个数组的大小，此函数原型如下： </p>
<pre class=" language-c"><code class="language-c"><span class="token keyword">int</span> <span class="token function">of_property_count_elems_of_size</span><span class="token punctuation">(</span><span class="token keyword">const</span> <span class="token keyword">struct</span> device_node <span class="token operator">*</span>np<span class="token punctuation">,</span><span class="token keyword">const</span> <span class="token keyword">char</span> <span class="token operator">*</span>propname<span class="token punctuation">,</span><span class="token keyword">int</span> elem_size<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
<h4 id="（3）读取-u8、-u16、-u32-和-u64-类型的数组数据"><a href="#（3）读取-u8、-u16、-u32-和-u64-类型的数组数据" class="headerlink" title="（3）读取 u8、 u16、 u32 和 u64 类型的数组数据"></a>（3）读取 u8、 u16、 u32 和 u64 类型的数组数据</h4><p><img src="https://s1.ax1x.com/2020/04/20/J3e0Kg.png" alt></p>
<h4 id="（4）读取-u8、-u16、-u32-和-u64-类型属性值"><a href="#（4）读取-u8、-u16、-u32-和-u64-类型属性值" class="headerlink" title="（4）读取 u8、 u16、 u32 和 u64 类型属性值"></a>（4）读取 u8、 u16、 u32 和 u64 类型属性值</h4><p><img src="https://s1.ax1x.com/2020/04/20/J3eBrQ.png" alt></p>
<h4 id="（5）of-property-read-string-函数"><a href="#（5）of-property-read-string-函数" class="headerlink" title="（5）of_property_read_string 函数"></a>（5）of_property_read_string 函数</h4><p>of_property_read_string 函数用于读取属性中字符串值，函数原型如下： </p>
<pre class=" language-c"><code class="language-c"><span class="token keyword">int</span> <span class="token function">of_property_read_string</span><span class="token punctuation">(</span><span class="token keyword">struct</span> device_node <span class="token operator">*</span>np<span class="token punctuation">,</span><span class="token keyword">const</span> <span class="token keyword">char</span> <span class="token operator">*</span>propname<span class="token punctuation">,</span><span class="token keyword">const</span> <span class="token keyword">char</span> <span class="token operator">*</span><span class="token operator">*</span>out_string<span class="token punctuation">)</span></code></pre>
<p>以上就是关于设备树的一些基础知识的整理学习，下一篇笔记我们再来一起学一下设备树的一些具体实验。</p>
<hr>
<p>我的个人博客：<a href="https://www.lizhengnian.cn/">https://www.lizhengnian.cn/</a></p>
<p>我的微信公众号：嵌入式大杂烩</p>
<p>我的CSDN博客：<a href="https://blog.csdn.net/zhengnianli" target="_blank" rel="noopener">https://blog.csdn.net/zhengnianli</a></p>
<p><img src="https://s2.ax1x.com/2019/06/11/VcSFJJ.md.png" alt></p>

            </div>
            <hr>

            
            <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.88rem;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-large waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fa fa-close"></i></a>
            <h4 class="reward-title">欢迎关注ZhengN的微信公众号</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <!--<ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微信公众号</a></li>
                    </ul>-->
					<!--
                    <div id="alipay">
                        <img src="" class="reward-img" alt="支付宝打赏二维码">
                    </div>
					-->
                    <div id="wechat">
                        <img src="/medias/reward/wechat.jpg" class="reward-img" alt="微信公众号二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>
            

            <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">

<div id="article-share">
    
    <div class="social-share" data-disabled="qzone" data-wechat-qrcode-helper="<p>微信里点“发现”->“扫一扫”二维码便可查看分享。</p>"></div>
    
</div>

<script src="/libs/share/js/social-share.min.js"></script>

            


        </div>
    </div>

    

    

    

    

    
        <style>
    .valine-card {
        margin: 1.5rem auto;
    }

    .valine-card .card-content {
        padding: 20px 20px 5px 20px;
    }

    #vcomments input[type=text],
    #vcomments input[type=email],
    #vcomments input[type=url],
    #vcomments textarea {
        box-sizing: border-box;
    }

    #vcomments p {
        margin: 2px 2px 10px;
        font-size: 1.05rem;
        line-height: 1.78rem;
    }

    #vcomments blockquote p {
        text-indent: 0.2rem;
    }

    #vcomments a {
        padding: 0 2px;
        color: #42b983;
        font-weight: 500;
        text-decoration: underline;
    }

    #vcomments img {
        max-width: 100%;
        height: auto;
        cursor: pointer;
    }

    #vcomments ol li {
        list-style-type: decimal;
    }

    #vcomments ol,
    ul {
        display: block;
        padding-left: 2em;
        word-spacing: 0.05rem;
    }

    #vcomments ul li,
    ol li {
        display: list-item;
        line-height: 1.8rem;
        font-size: 1rem;
    }

    #vcomments ul li {
        list-style-type: disc;
    }

    #vcomments ul ul li {
        list-style-type: circle;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    #vcomments table, th, td {
        border: 0;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments h1 {
        font-size: 1.85rem;
        font-weight: bold;
        line-height: 2.2rem;
    }

    #vcomments h2 {
        font-size: 1.65rem;
        font-weight: bold;
        line-height: 1.9rem;
    }

    #vcomments h3 {
        font-size: 1.45rem;
        font-weight: bold;
        line-height: 1.7rem;
    }

    #vcomments h4 {
        font-size: 1.25rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    #vcomments h5 {
        font-size: 1.1rem;
        font-weight: bold;
        line-height: 1.4rem;
    }

    #vcomments h6 {
        font-size: 1rem;
        line-height: 1.3rem;
    }

    #vcomments p {
        font-size: 1rem;
        line-height: 1.5rem;
    }

    #vcomments hr {
        margin: 12px 0;
        border: 0;
        border-top: 1px solid #ccc;
    }

    #vcomments blockquote {
        margin: 15px 0;
        border-left: 5px solid #42b983;
        padding: 1rem 0.8rem 0.3rem 0.8rem;
        color: #666;
        background-color: rgba(66, 185, 131, .1);
    }

    #vcomments pre {
        font-family: monospace, monospace;
        padding: 1.2em;
        margin: .5em 0;
        background: #272822;
        overflow: auto;
        border-radius: 0.3em;
        tab-size: 4;
    }

    #vcomments code {
        font-family: monospace, monospace;
        padding: 1px 3px;
        font-size: 0.92rem;
        color: #e96900;
        background-color: #f8f8f8;
        border-radius: 2px;
    }

    #vcomments pre code {
        font-family: monospace, monospace;
        padding: 0;
        color: #e8eaf6;
        background-color: #272822;
    }

    #vcomments pre[class*="language-"] {
        padding: 1.2em;
        margin: .5em 0;
    }

    #vcomments code[class*="language-"],
    pre[class*="language-"] {
        color: #e8eaf6;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }

    #vcomments b,
    strong {
        font-weight: bold;
    }

    #vcomments dfn {
        font-style: italic;
    }

    #vcomments small {
        font-size: 85%;
    }

    #vcomments cite {
        font-style: normal;
    }

    #vcomments mark {
        background-color: #fcf8e3;
        padding: .2em;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }
</style>

<div class="card valine-card" data-aos="fade-up">
    <div id="vcomments" class="card-content"></div>
</div>

<script src="/libs/valine/av-min.js"></script>
<script src="/libs/valine/Valine.min.js"></script>
<script>
    new Valine({
        el: '#vcomments',
        appId: 'Vc276uuqkd8y8heuqzShe9p1-gzGzoHsz',
        appKey: 'bUwy6lANpgeVdpcQamMtC8QD',
        notify: 'false' === 'true',
        verify: 'false' === 'true',
        visitor: 'true' === 'true',
        avatar: 'mm',
        pageSize: '10',
        lang: 'zh-cn',
        placeholder: '快来快活呀！^_^'
    });
</script>
    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6 overflow-policy" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fa fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/2020/04/23/linux-she-bei-shu-shi-li-fen-xi/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/22.jpg" class="responsive-img" alt="【Linux】设备树实例分析">
                        
                        <span class="card-title">【Linux】设备树实例分析</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            前言我们可以从LED程序中榨取很多知识：基本的驱动框架、驱动的简单分层、驱动的分层+分离思想、总线设备驱动模型、设备树等。这大多都是结合韦老师的教程学的，这篇笔记结合第6个demo（基于设备树）来学习、分析：

框图下面是LED程序的几个层
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="fa fa-clock-o fa-fw icon-date"></i>2020-04-23
                        </span>
                        <span class="publish-author">
                            
                            <i class="fa fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/Linux/" class="post-category" target="_blank">
                                    Linux
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/Linux/" target="_blank">
                        <span class="chip bg-color">Linux</span>
                    </a>
                    
                    <a href="/tags/设备树/" target="_blank">
                        <span class="chip bg-color">设备树</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6 overflow-policy" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fa fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/2020/04/10/linux-led-qu-dong-zong-xian-she-bei-qu-dong-mo-xing/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/0.jpg" class="responsive-img" alt="【Linux】LED驱动（总线设备驱动模型）">
                        
                        <span class="card-title">【Linux】LED驱动（总线设备驱动模型）</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            继续来点灯~
学了一段时间的嵌入式Linux发现LED程序挺香的。。
我们可以从LED程序中榨取很多知识：基本的驱动框架、驱动的简单分层、驱动的分层+分离思想、总线设备驱动模型、设备树等。这大多都是结合韦老师的教程学的，这篇笔记结合第5个d
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="fa fa-clock-o fa-fw icon-date"></i>2020-04-10
                            </span>
                        <span class="publish-author">
                            
                            <i class="fa fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/Linux/" class="post-category" target="_blank">
                                    Linux
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/Linux/" target="_blank">
                        <span class="chip bg-color">Linux</span>
                    </a>
                    
                    <a href="/tags/驱动/" target="_blank">
                        <span class="chip bg-color">驱动</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>
</div>



    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget">
            <div class="toc-title"><i class="fa fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fa fa-list"></i>
    </a>
</div>


<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            // headingsOffset: -205,
            headingSelector: 'h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).slideUp(500);
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).slideDown(500);
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>
    

</main>


<footer class="page-footer bg-color">
    <div class="container row center-align">
        <div class="col s12 m8 l8 copy-right">
            本站由&copy;<a href="https://zhengnianli.github.io/" target="_blank">ZhengNian</a>基于
            <a href="https://hexo.io/" target="_blank">Hexo</a> 的
            <a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">hexo-theme-matery</a>主题搭建.

            
                &nbsp;<i class="fa fa-area-chart"></i>&nbsp;站点总字数:&nbsp;
                <span class="white-color">187.2k</span>
            

            
			
                <br>
                
                <span id="busuanzi_container_site_pv">
                    <i class="fa fa-heart-o"></i>
                    本站总访问量 <span id="busuanzi_value_site_pv" class="white-color"></span>
                </span>
                
                
                <span id="busuanzi_container_site_uv">
                    <i class="fa fa-users"></i>
                    次,&nbsp;访客数 <span id="busuanzi_value_site_uv" class="white-color"></span> 人.
                </span>
                
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/zhengnianli" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fa fa-github"></i>
    </a>



    <a href="mailto:2238184039@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fa fa-envelope-open"></i>
    </a>



    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=2238184039" class="tooltipped" data-tooltip="QQ联系我: 2238184039" data-position="top" data-delay="50">
        <i class="fa fa-qq"></i>
    </a>



    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fa fa-rss"></i>
    </a>
</div>
    </div>
</footer>

<div class="progress-bar"></div>


<!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fa fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字" class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script src="/js/search.js"></script>
<script type="text/javascript">
$(function () {
    searchFunc("/" + "search.xml", 'searchInput', 'searchResult');
});
</script>
<!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fa fa-angle-up"></i>
    </a>
</div>


<script src="/libs/materialize/materialize.min.js"></script>
<script src="/libs/masonry/masonry.pkgd.min.js"></script>
<script src="/libs/aos/aos.js"></script>
<script src="/libs/scrollprogress/scrollProgress.min.js"></script>
<script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
<script src="/js/matery.js"></script>

<!-- Global site tag (gtag.js) - Google Analytics -->



    <script src="/libs/others/clicklove.js"></script>


    <script async src="/libs/others/busuanzi.pure.mini.js"></script>


</body>
</html>